@extends('layouts.back_stage')
@section('content')
    <div class="container">
        <div style="padding:20px 20px 20px 0;overflow:hidden;">
            <h3 style="float:left;">公司列表</h3>
            <a class="btn btn-primary" style="text-align: center;float: right;" href="/company/create">添加公司</a>
        </div>
        <table class="table">
            <thead>
            <tr>
                <th class="col-md-2">序号</th>
                <th class="col-md-3">公司名称</th>
                <!-- <th class="col-md-2">虚拟归属</th> -->
                <th class="col-md-2">备注</th>
                <th class="col-md-2">&nbsp;&nbsp;&nbsp;&nbsp;操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach($companies as $key => $company)
                <tr id="delete_{{$company->id}}">
                    <td> {{$key+1}}</td>
                    <td> {{ $company->company_name }}</td>
                    <!-- <td>{{ $areas[$company->area_id]  }}</td> -->
                    <td>{{ $company->comment }}</td>
                    <td>
                        <a href="/company/edit?id={{ $company->id }}" >编辑</a>
                        <a onclick="deleteCompany({{ $company->id }})" id="delete">删除</a>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        <div style="float: right">{{ $companies->links() }}</div>
    </div>
    <script>
        function deleteCompany(id){
            $(".oText").text("确定要删除吗？");
            $(".oMask").show();
            $(".oAnim").show();
            $(".oBtn0").attr("abc",id);
            $(".oBtn0").attr('id','');
            $(".oBtn0").attr('id','oDelete');
        }
        /*点确定*/
        $(document).on('click','#oDelete',function(){
            $(".oMask").hide();
            $(".oAnim").hide();
            var id=$(this).attr("abc");
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                type:'post',
                url:'/company/delete',
                data:{
                    'id':id
                },
                success:function (data) {
                    $(".faceImg").attr("src","/img/laugh.png");
                    $(".oHandle").text("删除成功");
                    $(".oSuccess").show(0).delay(1000).hide(0);
                    $('#delete_'+id).remove();
                }
            });
        });
    </script>
@endsection